package transportorderservice;

import java.text.SimpleDateFormat;
import java.util.Date;

import javax.jws.WebService;

import logging.Logger;

@WebService(targetNamespace = "http://transportorderservice/", endpointInterface = "transportorderservice.TransportOderService", portName = "TransportOrderServiceImplementationPort", serviceName = "TransportOrderServiceImplementationService")
public class TransportOrderServiceImplementation implements TransportOderService 
{
	private static final String DATE_FORMAT = "yyyyMMdd";
	
	public String orderTransport(String offerId)
	{
		Logger.logSeparationLine();
		Logger.log("TransportOrderService starts!", true);
		
		String trackingNumber = generateTrackingNumber(offerId);
		
		Logger.log("Shipping order for offering id [" + offerId + "] has been registered! Shipment tracking number is " +
				"[" + trackingNumber + "]", false);
		Logger.log("TransportOrderService ends!", true);
		Logger.logSeparationLine();
		
		return trackingNumber;
	}
	
	public static String generateTrackingNumber(String offerId)
	{
		String trackingNumber = "";
		Date dateRightNow = new Date();
		SimpleDateFormat myOwnDateFormat = new SimpleDateFormat(DATE_FORMAT);
		String dateRightNowInFormattedRepresentation = myOwnDateFormat.format(dateRightNow);
		trackingNumber = offerId.toLowerCase() + "#" + dateRightNowInFormattedRepresentation;
			
		return trackingNumber;
	}
}
